package math

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
	"reflect"
	"strings"
)

type AND[T interface{}] struct {
	base.NoOperandsInstruction
}

func (self *AND[T]) Execute(jFrame *rtda.JFrame) {
	stack := jFrame.OperandStack()
	e := reflect.TypeOf(self).Elem().String()
	etype := strings.ReplaceAll(strings.Split(e, "[")[1], "]", "")
	switch etype {
	case "int64":
		v2 := stack.PopLong()
		v1 := stack.PopLong()
		stack.PushLong(v1 & v2)
		break
	case "int32":
		v2 := stack.PopInt()
		v1 := stack.PopInt()
		stack.PushInt(v1 & v2)
		break
	}

}

type IAND struct {
	AND[int32]
}
type LAND struct {
	AND[int64]
}
